#coding=utf-8
"""
!/usr/bin/python3
@Author: Gao Shuo
@Time: 2018/8/10 11:20 
@ReadMe:重设图片大小，保持颜色不增加，即取最近的颜色
    Input: 
    Output: 重设大小后的图片
"""
from PIL import Image
import os.path
import  sys

# 尝试重设图片
def ResizeImage(filein, fileout, width, height, types):
  img = Image.open(filein)
  # out = img.resize((width, height),Image.ANTIALIAS) #resize image with high-quality
  out = img.resize((width, height), resample=Image.NEAREST) #resize image with high-quality
  # out = img.thumbnail(width,height)
  out.save(fileout, types)

if __name__ == "__main__":
  width = 400
  height = 240
  types = 'png'
  # path =r'C:\Users\THINKPAD\Desktop\数据组\技术表现\segnet\water\180813\label'
  # pathout =r'C:\Users\THINKPAD\Desktop\数据组\技术表现\segnet\water\180813\labelreshape'
  path = sys.argv[1]
  dest = sys.argv[2]
  li = os.listdir(path)

  for filepath in li:
      filein = os.path.join(path, filepath)
      fileout = os.path.join(dest, filepath)
      ResizeImage(filein, fileout, width, height, types)




